package com.ruoyi.web.controller.archive;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.PWareHouse;
import com.ruoyi.system.service.IPWareHouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.List;



/**
 * 仓库管理Controller
 *
 * @author ruoyi
 * @date 2024-09-07
 */
@Api(tags = "库房管理API")
@RestController
@RequestMapping("/archive/house")
public class PWareHouseController extends BaseController
{
    @Autowired
    private IPWareHouseService pWareHouseService;

    /**
     * 查询仓库管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:house:list')")
    @GetMapping("/list")
    public TableDataInfo list(PWareHouse pWareHouse)
    {
        startPage();
        List<PWareHouse> list = pWareHouseService.selectPWareHouseList(pWareHouse);
        return getDataTable(list);
    }

    @ApiOperation("查询所有库房")
    @GetMapping("/getList")
    public AjaxResult getList(PWareHouse pWareHouse)
    {
        return success(pWareHouseService.selectPWareHouseList(pWareHouse));
    }

    /**
     * 导出仓库管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:house:export')")
    @Log(title = "仓库管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PWareHouse pWareHouse)
    {
        List<PWareHouse> list = pWareHouseService.selectPWareHouseList(pWareHouse);
        ExcelUtil<PWareHouse> util = new ExcelUtil<PWareHouse>(PWareHouse.class);
        util.exportExcel(response, list, "仓库管理数据");
    }

    /**
     * 获取仓库管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:house:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pWareHouseService.selectPWareHouseById(id));
    }

    /**
     * 新增仓库管理
     */
    @PreAuthorize("@ss.hasPermi('system:house:add')")
    @Log(title = "仓库管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PWareHouse pWareHouse)
    {
        if(pWareHouseService.selectPWareHouseByCode(pWareHouse.getCode())!=null){
            return error("编号为:"+pWareHouse.getCode()+"库房已存在!");
        };
        return toAjax(pWareHouseService.insertPWareHouse(pWareHouse));
    }

    /**
     * 修改仓库管理
     */
    @PreAuthorize("@ss.hasPermi('system:house:edit')")
    @Log(title = "仓库管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PWareHouse pWareHouse)
    {
        return toAjax(pWareHouseService.updatePWareHouse(pWareHouse));
    }

    /**
     * 删除仓库管理
     */
    @PreAuthorize("@ss.hasPermi('system:house:remove')")
    @Log(title = "仓库管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pWareHouseService.deletePWareHouseByIds(ids));
    }





}
